<template>
  <terminal
    title="redis工具"
    context="redis"
    :show-header="false"
    :init-log="[
      { type: 'normal', content: '欢迎使用redis控制台...' },
      { type: 'normal', content: 'author: enge' }
    ]"
    @exec-cmd="onExecCmd"
  ></terminal>
</template>
<script setup lang="ts">
import Terminal from 'vue-web-terminal'
import { getCurrentInstance } from 'vue'
const context = getCurrentInstance()?.appContext.config.globalProperties

function onExecCmd(key, command, success, failed) {
  if (key === 'fail') {
    failed('Something wrong!!!')
  } else {
    context?.$api.PUT('/toolkit/redis/execute', { command: command }).then((res) => {
      for (let p in res.data) {
        success({
          type: 'normal',
          content: res.data[p]
        })
      }
    })
  }
}
</script>
